#include "widget.h"

#include <QLineEdit>
#include <QPlainTextEdit>
#include <QTextEdit>
#include <QTextCursor>
#include <QTextCharFormat>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    resize(1000, 800);

    //-------单行文本框QLineEdit的使用---------
//    QLineEdit *lineEdit = new QLineEdit(this);
//    lineEdit->move(100, 50);
//    lineEdit->resize(300, 30);

//    //lineEdit->setText("我爱王道");
//    //设置密码显示模式
//    lineEdit->setEchoMode(QLineEdit::Password);
//    //设置占位符文本
//    lineEdit->setPlaceholderText("请输入密码");

    //-------纯文本框QPlainTextEdit的使用---------
//    QPlainTextEdit *pte = new QPlainTextEdit(this);
//    pte->resize(800, 600);
//    pte->insertPlainText("福达康多发几款东方红郡啊哈发哈回复打两局客服电话打哈");
//    pte->setPlainText("等哈东方基金合法客服回答");

    QTextEdit *textEdit = new QTextEdit(this);
    textEdit->resize(800, 600);
    //textEdit->setText("输入QTextEdit的纯文本信息");
    // 使用占位符文本的时候，不要有数据，因为占位符问题就是
    //起提示作用的
    //textEdit->setPlaceholderText("hddhh");
//    textEdit->insertHtml("<a href='https://www.baidu.com/'>Click "
//                         "here</a> to visit our website.");
    textEdit->insertPlainText("this is a student");

    //通过textEdit对象获取光标对象
    QTextCursor curcor = textEdit->textCursor();
    //移动光标对象到文本的最前面
    curcor.movePosition(QTextCursor::Start);
    curcor.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor);
    curcor.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor);

    QTextCharFormat format;
    format.setFont(QFont("宋体", 50));
    format.setFontItalic(true);
    format.setBackground(QBrush(QColor(255, 0, 0)));//rgb
    format.setFontWeight(50);

    curcor.mergeCharFormat(format);
}

Widget::~Widget()
{
}

